package uml.GUI;

import java.awt.Container;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import uml.eventsystem.IObserver;
import uml.eventsystem.ISubject;
import uml.eventsystem.SubjectImpl;
import uml.eventsystem.events.UMLEventId;
import uml.objects.UMLObject;

public class UMLObjectButton extends JButton
{
	private UMLEventId m_eventID;
	/**
	 * Sets up a button made to look like the <tt>UMLObject</tt>
	 * @param umlObject
	 * @param event
	 */
	public UMLObjectButton(UMLObject umlObject, UMLEventId event)
	{
		m_eventID = event;
		umlObject.setVisible(true);
		//create a new image to draw the object to
		BufferedImage iconImage = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
		//get the graphics object of the image to draw to
		Graphics2D imageGraphics = iconImage.createGraphics();
		//paint the UMLObject to the images graphics
		umlObject.getComponent().print(imageGraphics);
		ImageIcon buttonIcon = new ImageIcon(iconImage);
		setMargin(new Insets(0,0,0,0));
		setIcon(buttonIcon);
		setSize(80,50);
		setBorderPainted(false);
	}
	/**
	 * returns the buttons <tt>UMLEventID</tt>
	 * @return
	 */
	public UMLEventId getUMLEventId()
	{
		return m_eventID;
	}
}
